package com.lzx.iteam.adapter;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.lzx.iteam.AttendanceCalendarActivity;
import com.lzx.iteam.AttendanceCountActivity;
import com.lzx.iteam.R;
import com.lzx.iteam.bean.AttendanceCountData;
import com.lzx.iteam.bean.AttendanceData;
import com.lzx.iteam.bean.AttendanceRankData;
import com.lzx.iteam.util.AllDialogUtil;

import java.util.ArrayList;

/**
 * Created by Megan on 16/4/8.
 */
public class AttendanceRankAdapter extends BaseAdapter {

    private Context mContext;
    private ArrayList<AttendanceRankData> attendanceRankDatas;

    public AttendanceRankAdapter(Context mContext) {
        this.mContext = mContext;
    }


    public void bindData(ArrayList<AttendanceRankData> attendanceRankDatas) {
        this.attendanceRankDatas = attendanceRankDatas;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return attendanceRankDatas==null?0:attendanceRankDatas.size();
    }

    @Override
    public Object getItem(int i) {
        return attendanceRankDatas==null?null:attendanceRankDatas.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        ViewHolder holder;
        final AttendanceRankData attendanceRankData = attendanceRankDatas.get(i);
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_attendance_rank, null);
            holder = new ViewHolder();
            holder.num = (TextView) convertView.findViewById(R.id.tv_attendance_rank_num);
            holder.name = (TextView) convertView.findViewById(R.id.tv_attendance_rank_name);
            holder.hour = (TextView) convertView.findViewById(R.id.tv_attendance_rank_hour);
            holder.mLlRoot = (LinearLayout) convertView.findViewById(R.id.attendance_rank_item_root);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        if(i%2==0){
            holder.mLlRoot.setBackgroundColor(mContext.getResources().getColor(R.color.schedule_bg));
        }else{
            holder.mLlRoot.setBackgroundColor(mContext.getResources().getColor(R.color.white));
        }
        holder.name.setText(attendanceRankData.getUserName());
        holder.num.setText(i+1+"");
        holder.hour.setText(attendanceRankData.getWorkHour()+"小时");


        return convertView;
    }

    class ViewHolder {
        TextView name, hour, num;
        LinearLayout mLlRoot;
    }


}
